import { PrismaClient } from "@prisma/client";
import { PlatformServe } from "./platform.ts";

const prisma = new PrismaClient();
const platform = new PlatformServe(prisma);
const account = new PlatformServe(prisma);

const handleOperation = <T>(instance: PlatformServe, operation: 'add' | 'remove', params?: T) => {
    return async () => {
        try {
            await instance[operation](params);
        } catch (error) {
            console.error(`${operation} 操作失败:`, error);
            throw new Error(`Failed to ${operation} platform`);
        }
    };
};

// API 操作函数
export const apiPlatform ={
    add: <T>(params?: T) => handleOperation(platform, 'add', params),
    remove: <T>(params?: T) => handleOperation(platform, 'remove', params),
}

export const apiAccount = () => ({
    add: <T>(params?: T) => handleOperation(account, 'add', params),
    remove: <T>(params?: T) => handleOperation(account, 'remove', params),
});
